package Sort.面试;

/**
 * 返回字符串中出现次数最多的字符
 */
public class InStringMaxChar {
    public static void main(String[] args) {
        String str = "aacacaccaacccaaabbbbbbccccsdfd";
        System.out.println(maxChar(str));
    }

    public static char maxChar(String text){
        char[] chars = text.toCharArray();
        int temp = 0;
        char a = chars[0];
        for (int i = 0; i < chars.length; i++){
            int length = 0;
            for(int j = 0; j < chars.length; j++){
                if(i != j && chars[i]== chars[j]){
                    length ++;
                }
                if(temp < length){
                    temp = length;
                    a = chars[j];
                }
            }
        }
        return a;
    }
}
